package com.zj;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLDecoder;
import java.net.URLEncoder;

@WebServlet("/cookie")
public class CookieServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String values = "张三";
        values = URLEncoder.encode(values,"UTF-8");
        System.out.println(values);
        Cookie cookie = new Cookie("username",values);
        cookie.setMaxAge(10000);
        resp.addCookie(cookie);
//        String value = URLEncoder.encode("小狗蛋","UTF-8");
//        System.out.println(value);
//        System.out.println(URLDecoder.decode(value,"UTF-8"));
    }
}
